package com.hexiang.rocketmq.controller;

import com.hexiang.rocketmq.mq.producer.*;
import com.hexiang.rocketmq.mq.producer.transaction.DemoSpringTransactionMQProducer;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("rocketmq")
public class SpringMessageRocketMQController {

    @Resource
    private DemoSpringMQProducer demoSpringMQProducer;

    @Resource
    private OrderProducer orderProducer;

    @Resource
    private DemoSpringTransactionMQProducer demoSpringTransactionMQProducer;

    @Resource
    private DelayTimeMessageProducer delayTimeMessageProducer;

    @Resource
    private SimpleBatchSpringMessageProducer simpleBatchSpringMessageProducer;

    @Resource
    private ComplexBatchSpringMessageProducer complexBatchSpringMessageProducer;

    @Resource
    private TagFilterProducer tagFilterProducer;

    @Resource
    private SqlFilterProducer sqlFilterProducer;

    @Resource
    private RpcProducer rpcProducer;
    @Resource
    private TraceProducer traceProducer;

    @RequestMapping("/spring/asyncSendAndReceive/{msg}")
    public String asyncSendAndReceive(@PathVariable String msg) {
        rpcProducer.asyncSendAndReceive(msg);
        return "ok";
    }

    @RequestMapping("/spring/sendAndReceive/{msg}")
    public String sendAndReceive(@PathVariable String msg) {
        rpcProducer.sendAndReceive(msg);
        return "ok";
    }

    @RequestMapping("/spring/send/{msg}")
    public String sendSpring(@PathVariable String msg) {
        demoSpringMQProducer.sendMsg(msg);
        return "ok";
    }

    @RequestMapping("/spring/sendWithTrace/{msg}")
    public String sendWithTrace(@PathVariable String msg) {
        traceProducer.sendMsg(msg);
        return "ok";
    }


    @RequestMapping("/spring/sendTransactionMsg/{msg}")
    public String sendTransactionMsg(@PathVariable String msg) {
        demoSpringTransactionMQProducer.sendMessageInTransaction(msg);
        return "ok";
    }


    @RequestMapping("/spring/sendOrderMsg")
    public String sendOrderMsg() {
        orderProducer.sendOrderMsg();
        return "ok";
    }

    @RequestMapping("/spring/sendDelayTimeMsg/{msg}")
    public String sendDelayTimeMsg(@PathVariable String msg) {
        delayTimeMessageProducer.sendDelayTimeMsg(msg);
        return "ok";
    }

    @RequestMapping("/spring/sendBatchMsg")
    public String sendBatchMsg() {
        simpleBatchSpringMessageProducer.sendBatchMsg();
        return "ok";
    }

    @RequestMapping("/spring/sendComplexBatchMsg")
    public String sendComplexBatchMsg() {
        complexBatchSpringMessageProducer.sendComplexBatchMsg();
        return "ok";
    }

    @RequestMapping("/spring/sendMsgByTag")
    public String sendMsgByTag() {
        tagFilterProducer.sendMsgByTag();
        return "ok";
    }

    @RequestMapping("/spring/sendMsgBySql")
    public String sendMsgBySql() {
        sqlFilterProducer.sendMsgBySql();
        return "ok";
    }
}
